package com.yang.mall.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yang.mall.dto.LiveOrderMasterDTO;
import com.yang.mall.dto.QueryOrderDTO;
import com.yang.mall.dto.QueryStatisticsDTO;
import com.yang.mall.entity.LiveOrder;
import com.yang.mall.entity.OLResponse;
import com.yang.mall.entity.QueryRequest;
import com.yang.mall.service.ILiveOrderService;
import com.yang.mall.vo.LiveOrderVO;
import com.yang.mall.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author kadorlin
 * @since 2022-10-21
 */
@Api(tags = "【小程序】订单模块")
@RestController
@RequestMapping("/h5/order")
public class LiveOrderController {

    @Autowired
    public ILiveOrderService liveOrderService;

    @ApiOperation("提交订单")
    @PostMapping("submit")
    public OLResponse<LiveOrder> submit(@RequestBody LiveOrderMasterDTO liveOrderMasterDTO){
        return new OLResponse().success(liveOrderService.submit(liveOrderMasterDTO));
    }

    @ApiOperation("订单列表")
    @GetMapping("list")
    public OLResponse<IPage<LiveOrderVO>> orderList(QueryOrderDTO queryOrderDTO){
        return new OLResponse().success(liveOrderService.orderList(queryOrderDTO));
    }

    @ApiOperation("订单明细")
    @GetMapping("detail/{orderId}")
    public OLResponse<LiveOrderVO> detail(@PathVariable Long orderId){
        return new OLResponse().success(liveOrderService.detail(orderId));
    }

    @ApiOperation("取消订单")
    @PutMapping("cancel/{orderId}")
    public OLResponse cancel(@PathVariable Long orderId){
        liveOrderService.cancel(orderId);
        return new OLResponse().success();
    }

    @ApiOperation("订单统计")
    @GetMapping("statistics")
    public OLResponse<OrderStatisticsVO> statistics(QueryStatisticsDTO queryStatisticsDTO){
        return new OLResponse().success(liveOrderService.statistics(queryStatisticsDTO));
    }

}
